let app = getApp()
var {
  Api
} = require('../../api/api')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    itemss: [
      {value: 1, name: '刷题',checked: 'true'},
      {value: 2, name: '背题'}
    ],
    nzidtype:false,//下一章节状态
    nzidsss:[],//所有章节信息
    nzid:'',//下章节id
    nkid:'',//下课程id
    ntid:'',//下题库id=========这三个都是正常刷题进来的
    zid:'',//章节id
    kid:'',//课程id
    tid:'',//题库id=========这三个都是正常刷题进来的
    vague:false,//是否模糊
    submit:false,//是否提交
    card:true,//答题卡是否有type为4时不展示为2也不展示3也不显示
    ye:false,//是否为夜间模式
    show:false,//答题卡是否出来
    tabid:0,//多问的时候用的着，type=3和5
    questionNumber:0,//用来记录当前可以跳转到哪道题
    items:[],//题目id列表
    num:0,//题目id索引
    detail:'',//题目详情
    type:1,//1为章节列表进的2就是考试//3為错题本进来的//4是直接重笔记本里和考同学进来的，将会直接显示答案

    typeitemsss:1,//刷题模式  1 刷题  2 背题

    comment:[],//评论列表
    subject:[],//笔记列表
    my_answer:[],//我选择的答案
    daitem:[],//题卡信息
    items2:[],//用来储存考试的信息
    reque:false,//是否提交中
    domain: Api.domain,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  
  onLoad: function (options) {
    
    /*
    let itemss= [
      {value: 1, name: '刷题',checked: 'true'},
      {value: 2, name: '背题'}
    ];
    
    this.setData({
      itemss:itemss
    })
    */
    /*
    this.setData({
      nzid:options.nzid,
      ntid:options.ntid,
      nkid:options.nkid,
    })
    */

    if(options.type==1){//章节进来的
      //下一章节
      let nzidsss=JSON.parse(options.nzids);
      this.setData({
          nzidsss:nzidsss
      })
    
    for (var i = 0; i < nzidsss.length; i++) {
      if(nzidsss[i].id==options.zid){ //当前id
         //下一个id
         
         if(typeof(nzidsss[i+1])!=="undefined"){  //关闭下一章状态
          let nzzid=nzidsss[i+1].id;
          this.setData({
            nzidtype:true
          })
         }
         break;
      }
  }




      this.setData({
        num:Number(options.num),
        zid:options.zid,
        tid:options.tid,
        kid:options.kid,
        type:1,
        questionNumber:Number(options.num)
      })
      this.type1items(options.zid,options.tid,options.kid)
      this.record(options.zid,options.tid,options.kid)

      console.log(this.data.type,"tttyytytyttyyt",this.data.submit);

    }
    if(options.type==2){//随机进来的开始考试
      this.examination(options.tid)
      app.time1 = this.getNowTime()//获取考试开始时间
      this.setData({
        num:0,
        type:2,
        card:false
      })
    }
    if(options.type==3){//错题本进来的
      this.setData({
        num:Number(options.num),
        zid:options.zid,
        tid:options.tid,
        kid:options.kid,
        type:3,
        card:false
      })
      this.wrongTopic(options.zid,options.tid,options.kid)
    }
    if(options.type==4){//笔记本详情和分享页面进来的
      this.setData({
        num:0,
        items:[options.id],
        submit:true,
        type:4,
        card:false
      })
      this.tidetail()
    }
    wx.showShareMenu({
      withShareTicket: true,
      menus: ['shareAppMessage', 'shareTimeline']
    })
  },

  /*************刷题模式切换************************ */
  radioChange(e) {
    console.log('radio发生change事件，携带value值为：', e.detail.value)
    let itemss = this.data.itemss
    for (let i = 0, len = itemss.length; i < len; ++i) {
      itemss[i].checked = itemss[i].value == e.detail.value
    }
    this.setData({
      itemss
    })
    if(e.detail.value==1){ //刷题模式

      console.log(this.data.my_answer.length,"dddddddddd");

      if(this.data.my_answer.length==0){ //没有填写答案时
        this.setData({
          submit:false,
          typeitemsss:1
        })
      }else{ //填写了答案
        this.setData({
          submit:true,
          typeitemsss:1
        })
      }
      
    }else if(e.detail.value==2){//背题模式
      this.setData({
        submit:true,
        typeitemsss:2
      })
    }
    
    this.tidetail();
    console.log(this.data.type);
    console.log(this.data.detail);
    console.log(this.data.my_answer);
  },
  
  

  record(zid,tid,kid){//从正常章节进来的题卡信息
    let params = {
      library_id:tid||'',
      course_id:kid||'',
      chapter_id:zid||'',
    }
    wx.$http.get(wx.$get.card_subject,params).then(res=>{
     
      let ress = res
      let daitem = [
        {name:'单选题',children:[]},
        {name:'多选题',children:[]},
        {name:'阅读多问题',children:[]},
        {name:'翻译题',children:[]},
        {name:'分析题',children:[]},
        {name:'作文题',children:[]},
      ]
      for(let i = 0;i<ress.length;i++){
        ress[i].index = i+1
        if(ress[i].type==1){
          daitem[0].children =  daitem[0].children.concat(res[i])
        }
        if(ress[i].type==2){
          daitem[1].children =  daitem[1].children.concat(res[i])
        }
        if(ress[i].type==3){
          daitem[2].children =  daitem[2].children.concat(res[i])
        }
        if(ress[i].type==4){
          daitem[3].children =  daitem[3].children.concat(res[i])
        }
        if(ress[i].type==5){
          daitem[4].children =  daitem[4].children.concat(res[i])
        }
        if(ress[i].type==6){
          daitem[5].children =  daitem[5].children.concat(res[i])
        }
      }
      this.setData({
        daitem:daitem
      })
      console.log(daitem,'答题卡信息')
    })
  },
  type1items(zid,tid,kid){//章节列表进来的题id
    let params = {
      member_id:wx.$cache.get('member_id'),
      library_id:tid||'',
      course_id:kid||'',
      chapter_id:zid||''
    }
    wx.$http.get(wx.$get.subject_ids,params).then(res=>{
      console.log(res,'章节列表进来的所有题id')
      let num=0
      res.forEach(item=>{
        if(item.is_subject_log==1){
          num++
        }

      })
      console.log(num,'做题')
      let ress =[]
      for(let i =0;i<res.length;i++){
        ress=ress.concat(res[i].id)
      }
      this.setData({
        items:ress
      })
      this.tidetail()
    })
  },
  examination(tid){//获取考试所有id
    let params = {
      library_id:tid
    }
    wx.$http.get(wx.$get.examination,params).then(res=>{
      console.log(res,'考试列表')
      let ress = res
      let items = [] //所有题目id
      let daitem = [
        {name:'单选题',children:[]},
        {name:'多选题',children:[]},
        {name:'阅读多问题',children:[]},
        {name:'翻译题',children:[]},
        {name:'分析题',children:[]},
        {name:'作文题',children:[]},
      ]
      for(let i = 0;i<ress.length;i++){
        ress[i].index = i+1
        ress[i].subject_log = []
        if(ress[i].type==1){
          daitem[0].children =  daitem[0].children.concat(res[i])
        }
        if(ress[i].type==2){
          daitem[1].children =  daitem[1].children.concat(res[i])
        }
        if(ress[i].type==3){
          daitem[2].children =  daitem[2].children.concat(res[i])
        }
        if(ress[i].type==4){
          daitem[3].children =  daitem[3].children.concat(res[i])
        }
        if(ress[i].type==5){
          daitem[4].children =  daitem[4].children.concat(res[i])
        }
        if(ress[i].type==6){
          daitem[5].children =  daitem[5].children.concat(res[i])
        }
      }
      for(let i =0;i<ress.length;i++){
        items = items.concat(ress[i].id)
      }
      this.setData({
        items,
        items2:ress,
        daitem
      })
      console.log(daitem,'题卡信息',items,'items的信息',this.data.num,'num的信息')
      this.tidetail()
    })
  },
  wrongTopic(zid,tid,kid){//错题本的所有id
    let type = 2
    if(zid==0){
      type=1
    }
    let params = {
      library_ids:tid||'',
      course_ids:kid||'',
      chapter_ids:zid||'',
      page:1,
      page_size:300,
      type
    }
    wx.$http.post(wx.$get.wrong_log_my,params).then(res=>{
      console.log(res,'错题本所有id')
      for (var i = 0;i < res.length; i++){
        if (!res[i].id){
            res.splice(i,1);
        }
     
     }

      let items = []
      for(let i =0;i<res.length;i++){
        items=items.concat(res[i].id)
      }
      // let daitem = [
      //   {name:'单选题',children:[]},
      //   {name:'多选题',children:[]},
      //   {name:'阅读多问题',children:[]},
      //   {name:'翻译题',children:[]},
      //   {name:'分析题',children:[]},
      //   {name:'作文题',children:[]},
      // ]
      // for(let i = 0;i<ress.length;i++){
      //   ress[i].index = i+1
      //   ress[i].subject_log = []
      //   if(ress[i].type==1){
      //     daitem[0].children =  daitem[0].children.concat(res[i])
      //   }
      //   if(ress[i].type==2){
      //     daitem[1].children =  daitem[1].children.concat(res[i])
      //   }
      //   if(ress[i].type==3){
      //     daitem[2].children =  daitem[2].children.concat(res[i])
      //   }
      //   if(ress[i].type==4){
      //     daitem[3].children =  daitem[3].children.concat(res[i])
      //   }
      //   if(ress[i].type==5){
      //     daitem[4].children =  daitem[4].children.concat(res[i])
      //   }
      //   if(ress[i].type==6){
      //     daitem[5].children =  daitem[5].children.concat(res[i])
      //   }
      // }
      this.setData({
        items,
      })
      this.tidetail()
    })
  },
  tidetail(){//题目解析
    /*this.setData({
      submit:false,
    })
    */
    let params = {
      member_id:wx.$cache.get('member_id'),
      subject_id:this.data.items[this.data.num]
    }
    wx.$http.get(wx.$get.subject_info,params).then(res=>{
      console.log(res,'题目解析')
      res.right_percentage =parseInt(res.correct_num/res.total_num*100)

      if(this.data.type==1&&wx.$cache.get('answer')){
        this.setData({
          vague:true
        })
      }
      if(res.subject_log&&this.data.type==1){//表示这道题已经做过了，并且是正常章节进来的，直接显示答案

        console.log("zzzzzzzzz",res);

        this.setData({
          detail:res
        })
        let my_answer = []//我选的答案
        if(res.type==3||res.type==5){//多问题的答案是数组，需要转过来
          my_answer =JSON.parse(res.subject_log.my_answer)
          console.log(my_answer,'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx')
          this.setData({
            my_answer,
            submit:true,
          })
        }else{
          my_answer = res.subject_log.my_answer.split(',')

          console.log("6666666666665656565656",res.subject_log.my_answer);

          this.setData({
            submit:true,
            my_answer
          })
        }
      }
      if(this.data.type==2){//为考试需要单独处理数组//需要记录一下选择的问题
        if(res.type==1||res.type==2){
          this.setData({//保存这到题的正确答案，交卷的时候比对
            [`items2[${this.data.num}].correct_answer`]:res.correct_answer,
            [`items2[${this.data.num}].fraction_total`]:res.fraction_total,//这道题一共多少分
          })
          if(this.data.items2[this.data.num].subject_log.length!=0){//单选多选处理
            for(let i =0;i<this.data.items2[this.data.num].subject_log.my_answer.length;i++){
              for(let j = 0;j<res.option_str.length;j++){
                if(this.data.items2[this.data.num].subject_log.my_answer[i]==res.option_str[j].option){
                  res.option_str[j].flage = true
                }
              }
            }
          }
        }
        if(res.type==4||res.type==6){
          this.setData({//保存这到题的正确答案，交卷的时候比对
            [`items2[${this.data.num}].correct_answer`]:res.fraction_total,
            [`items2[${this.data.num}].fraction_total`]:res.fraction_total,
          })
          if(this.data.items2[this.data.num].fen){//自己填分处理
            res.my_answer = this.data.items2[this.data.num].fen
          }
        }
        if(res.type==3||res.type==5){
          this.setData({
            [`items2[${this.data.num}].my_answerlength`]:res.little_question_json.length
          })
        }
        this.setData({
          detail:res,
          [`items2[${this.data.num}].type`]:res.type,//记录这道题是什么题
        })
      }else{  //直接跳转的，且 还是没有做过的

        console.log("wwwwwwwwwww",res);
        console.log("wwwwwwwwwww1111",this.data.type);
        res.iidddd=res.id;
        this.setData({
          detail:res
        })
      }
      this.pinglist()
      this.bilist()
    })
  },
  goye() { //夜间模式的切换
    this.setData({
      ye: !this.data.ye
    })
    if (this.data.ye) {
      wx.setNavigationBarColor({
        frontColor: '#ffffff',
        backgroundColor: '#202020',
        animation: {
          duration: 400,
          timingFunc: 'easeIn'
        }
      })
    } else {
      wx.setNavigationBarColor({
        frontColor: '#000000',
        backgroundColor: 'white',
      })
    }
  },
  show() { //答题卡显示出来
    if(this.data.type==1){//当只有type==1时答题卡才调用刷新题卡信息
      this.record(this.data.zid,this.data.tid,this.data.kid)
    }
    this.setData({
      show: true
    })
  },
  pinglist(){//评论列表
    let params = {
      member_id:wx.$cache.get('member_id'),
      subject_id:this.data.items[this.data.num],
      page:1,
      page_size:3
    }
    wx.$http.get(wx.$get.comment_list,params).then(res=>{
      console.log(res,'评论列表')
      this.setData({
        comment:res
      })
    })
  },
  zhan(e) { //评论点赞
    const {
      id,type
    } = e.currentTarget.dataset
    var params = {
      log_id: id,
      type
    }
    wx.$http.get(wx.$get.give_log,params).then(res=>{
      console.log(res,'点赞')
      if(type==2){
        this.pinglist()
      }
      if(type==1){
        this.bilist()
      }
    })
  },
  gocomment(){//跳转评论列表
    wx.navigateTo({
      url: `/pages/comment/comment?id=${this.data.items[this.data.num]}`,
    })
  },
  bilist(){//笔记列表
    let params = {
      member_id:wx.$cache.get('member_id'),
      subject_ids:this.data.items[this.data.num],
      // course_id:this.data.detail.course_id,
      // chapter_id:this.data.detail.chapter_id,
      // library_id:this.data.detail.library_id,
      page:1,
      page_size:3
    }
    wx.$http.get(wx.$get.note_list,params).then(res=>{
      console.log(res,'笔记列表')
      this.setData({
        subject: res,
        reque:false,
      })
    })
  },
  cha() { //查看全部笔记
    wx.navigateTo({
      url: '/pages/quanbj/quanbj?id=' + this.data.items[this.data.num],
    })
  },
  gobaocuo() { //去我要报错页面
    app.title = this.data.detail.subject_str
    wx.navigateTo({
      url: '/pages/mistake/mistake?id=' + this.data.items[this.data.num],
    })
  },
  gomynote(){//跳转我的笔记
    wx.navigateTo({
      url: '/pages/myNotes/myNotes?id='+this.data.items[this.data.num],
    })
  },
  gonewnote(){//跳转笔记列表
    wx.navigateTo({
      url: '/pages/newnote/newnote?id='+this.data.items[this.data.num],
    })
  },
  submit(){//提交答案
    if(this.data.detail.type==1||this.data.detail.type==2){//单选多选
      let detail = this.selectComponent('#exam').data.detail
      let my_answer = []//我选择的答案
      let answer = []//正确答案
      let is_correct = 2//是否正确1是2否
      for(let i =0;i<detail.option_str.length;i++){
        if(detail.option_str[i].is_correct==1){
          answer = answer.concat(detail.option_str[i].option)
        }
        if(detail.option_str[i].flage){
          my_answer = my_answer.concat(detail.option_str[i].option)
        }
      }
      
      if(my_answer.length<=1 && this.data.detail.type==2){ //多选直选一个就提示
        wx.showToast({
          title: '此题为多选题',
          icon:'none'
        })
        return
      }



      if(my_answer.length==0){
        wx.showToast({
          title: '请选择答案',
          icon:'none'
        })
        return
      }
      if(my_answer.toString()==answer.toString()){
        is_correct=1
      }

      this.submitfang(my_answer,is_correct,'')//提交答案请求

      

    }
    if(this.data.detail.type==4||this.data.detail.type==6){//分析和翻译题
      let detail = this.selectComponent('#exam2').data
      let my_answer = detail.fen//我选择的答案
      this.submitfang(my_answer,1,'')
    }
    if(this.data.detail.type==3){//阅读
      let my_answer = []//我选择的答案
      let is_correct = 2//是否正确1是2否
      let zheng = []//装所有正确答案
      let zheng2 = []//装所有选择的答案
      let detail = this.selectComponent('#exam3').data.detail
      for(let i = 0;i<detail.little_question_json.length;i++){
        zheng=zheng.concat(detail.little_question_json[i].correct_answer)
        my_answer = my_answer.concat([{answer:''}])
        for(let j = 0;j<detail.little_question_json[i].option_str.length;j++){
          if(detail.little_question_json[i].option_str[j].flage){
            zheng2 = zheng2.concat(detail.little_question_json[i].option_str[j].option)
            my_answer[i].answer =detail.little_question_json[i].option_str[j].option
          }
        }
      }
      if(zheng.length!=zheng2.length){
        wx.showToast({
          title: '每个小问的答案都要选择',
          icon:'none'
        })
        return
      }
      if(zheng.toString()==zheng2.toString()){
        is_correct =1
      }
      my_answer = JSON.stringify(my_answer)
      this.submitfang(my_answer,is_correct,'')
    }
    if(this.data.detail.type==5){//卓文
      let detail = this.selectComponent('#exam3').data
      let my_answer = JSON.stringify(detail.fen2) //我选择的分数
      this.submitfang(my_answer,1,'')
    }
    
  },
  submitfang(my_answer,is_correct,little_question_json){//提交答案方法
     console.log("888888888888777777777777777777777rrrrrrrrrrrrrrr",this.data.detail);
     if(is_correct==1){ //正确
      this.setData({
        'detail.is_wrong':2
      })
     }else{
      this.setData({ //错误
        'detail.is_wrong':1
      })
     }
 this.setData({
   reque:true,
 })
    let params = {
      subject_id:this.data.items[this.data.num],
      my_answer:my_answer.toString(),
      is_correct,
      little_question_json:little_question_json,
      wid:2
    }
    wx.$http.get(wx.$get.make_question,params).then(res=>{
      console.log(res,'做题')
      if(this.data.type==1){
        if(this.data.num>this.data.questionNumber){
          this.setData({
            questionNumber:this.data.num
          })
        }
      }
      if(wx.$cache.get('she')&&this.data.type==1&&is_correct==1){//答对了直接下一题
        if(this.data.num+1==this.data.items.length){
          wx.showToast({
            title: '没有下一题了!',
            icon:'none'
          })
        }else{
          this.next()
          return
        }
      }
      if(wx.$cache.get('yin')&&this.data.type==1){//做题播放音频
        if(is_correct==1){
          this.zheng()
        }
        if(is_correct==2){
          this.cuowu()
        }
      }
      if(this.data.detail.type==3||this.data.detail.type==5){
        this.setData({
          submit:true,
          my_answer:JSON.parse(my_answer)
        })
      }else{
        this.setData({
          submit:true,
          my_answer:my_answer
        })
      }
      this.setData({
        reque:false,
      })
    }).catch(err=>{
      this.setData({
        reque:false,
      })
    })
  },
  goxiaa(e){//知识点
console.log(e.currentTarget.dataset.index)

console.log(this.data.detail.subject_knowledge);

app.globalData.content=this.data.detail.subject_knowledge[e.currentTarget.dataset.index].content


wx.navigateTo({
  url: '/pages/waparse/waparse?title=' + this.data.detail.subject_knowledge[e.currentTarget.dataset.index].title + '&is_url=' + 1,
})


  },

  /************
   * 下一章
   * nzid:'',//章节id
   * nkid:'',//课程id
   * ntid:'',//题库id=========这三个都是正常刷题进来的
   * ******************** */
  nextzhang(){
    let _this=this;
    wx.showModal({
      title: '下一章',
      content: '是否确认进入下一章节？',
      success(res) {
        if (res.confirm) {
          let zid=_this.data.zid;
          let kid=_this.data.kid;
          let tid=_this.data.tid;
          let nzidsss=_this.data.nzidsss;////所有章节信息
           let nzidss=JSON.stringify(nzidsss);
           for (var i = 0; i < nzidsss.length; i++) {
              if(nzidsss[i].id==zid){ //当前id
                 //下一个id
                 let nzzid=nzidsss[i+1].id;
                 if(typeof(nzzid)!=="undefined"){
                  let nnzid=nzzid;
                 
                  /*
                  _this.setData({
                    num:0,
                    zid:nnzid,
                    type:1,
                    questionNumber:0
                    





                  })
                  */
                 // _this.type1items(nnzid,tid,kid);
                 // _this.record(nnzid,tid,kid);
                  //_this.gun();

                  let type=_this.data.type;
                  wx.redirectTo({
                    url: `/pages/brushTopic/brushTopic?zid=${nnzid}&kid=${kid}&tid=${tid}&type=${type}&num=0&nzids=${nzidss}`,
                  })
                 }else{  //无下一章
                  _this.setData({
                    nzidtype:false
                  })
                 }
                 
                 break;
              }
          }
        } else if (res.cancel) {
          console.log('用户点击取消')
        }
      }
    })


    
  },

  next(){//下一题
    this.setData({
      my_answer:[]
    })
    if(this.data.itemss["1"].checked){
      this.setData({
        num:this.data.num+=1,
        submit:true
      })
    }else{
      this.setData({
        num:this.data.num+=1,
        submit:false
      })
    }
    
    this.gun()
    this.tidetail()
  },
  shang(){//上一题
    
    if(this.data.itemss["1"].checked){
      this.setData({
        num:this.data.num-=1,
        submit:true
      })
    }else{
      if(this.data.type==3){
        this.setData({
          num:this.data.num-=1,
          submit:true
        })
      }else{
        this.setData({
          num:this.data.num-=1,
          submit:false
        })
      }
      
    }

    this.gun()
    this.tidetail()
  },
  zheng() { //正确音频
    var innerAudioContext = wx.createInnerAudioContext();
    audioPlay()
    function audioPlay() {
      innerAudioContext.src = wx.$cache.get('can').correct_music;
      innerAudioContext.play();
      console.log('1')
    }
  },
  cuowu() { //错误音频
    console.log('cuo')
    var innerAudioContext = wx.createInnerAudioContext();
    audioPlay2()
    function audioPlay2() {
      innerAudioContext.src = wx.$cache.get('can').error_music;
      console.log(wx.$cache.get('can').error_music)
      innerAudioContext.play();
      console.log('2')
    }
  },
  jiao(){//叫卷
    let {items2} = this.data
    let arr = []
    for(let i =0;i<items2.length;i++){
      if(items2[i].is_correct!=1){
        arr = arr.concat(1)
      }
    }
    let tips = arr.length==0?'你确定要交卷吗？':'你还有'+arr.length+'道题没做,确定要交卷吗？'
    wx.showModal({
      title: '提示',
      content: tips,
      success:(res)=> {
        if (res.confirm) {
          app.items2 = items2
          app.items = this.data.items
          app.time2 = this.getNowTime()
          
          /***************批量添加错题***************/
          let params = {
            subject_data:this.data.items2,
            wid:2
          }
          wx.$http.get(wx.$get.make_wrong_log,params).then(res=>{
            console.log(res,'加入错题11111111')
            
          })

          
          wx.redirectTo({
            url:'/pages/examreport/examreport'
          })
          
        }
      }
    })
    console.log(this.data.items2,'交卷的qqq题')
  },
   // 获取当前时间
   getNowTime () {
    let dateTime
    let yy = new Date().getFullYear()
    let mm = new Date().getMonth() + 1
    let dd = new Date().getDate()
    let hh = new Date().getHours()
    let mf = new Date().getMinutes() < 10 ? '0' + new Date().getMinutes()
      :
      new Date().getMinutes()
    let ss = new Date().getSeconds() < 10 ? '0' + new Date().getSeconds()
      :
      new Date().getSeconds()
    dateTime = yy + '/' + mm + '/' + dd + ' ' + hh + ':' + mf + ':' + ss
    console.log(dateTime)
    return dateTime
  },
  addjia(e){//加入错题移除错题
    let {flage} = e.currentTarget.dataset
    if(flage==2){
      let params = {
        subject_id:this.data.items[this.data.num]
      }
      wx.$http.get(wx.$get.wrong_log_add,params).then(res=>{
        console.log(res,'加入错题')
        this.setData({
          'detail.is_wrong':1
        })
      })
    }else{
      let params = {
        subject_id:this.data.items[this.data.num]
      }
      wx.$http.get(wx.$get.wrong_log_del,params).then(res=>{
        console.log(res,'移除错题')
        if(this.data.type==3){
          this.setData({
            'detail.is_wrong':4
          })
        }else{
          this.setData({
            'detail.is_wrong':2
          })
        }
        

        wx.showToast({
          title: '移除成功',
          icon: 'success',
          duration: 2000,
          complete (res){
           // wx.redirectTo({
           //   url:'/pages/myMistake/myMistake'
//})
          }
        })
      })
    }
  },
  gun(){//屏幕滚到最上面
    wx.pageScrollTo({
      scrollTop: 0
    });
  },
  tidetail2(){//题目解析只用来刷新当前评论笔记数量的
    let params = {
      member_id:wx.$cache.get('member_id'),
      subject_id:this.data.items[this.data.num]
    }
    wx.$http.get(wx.$get.subject_info,params).then(res=>{
      console.log(res,'题目解析')
     this.setData({
       'detail.comment_num':res.comment_num,
       'detail.note_num':res.note_num
     })
      this.pinglist()
      this.bilist()
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
      
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function (res) {
    if (res.from === 'button') {
      return {
        title: wx.$cache.get('fx').title,
        imageUrl: wx.$cache.get('fx').img, // 图片 URL
        path: `/pages/brushTopic/brushTopic?type=4&pid=${wx.$cache.get('member_id')}&id=${this.data.items[this.data.num]}`
      }
    } else {
      return{
        title:wx.$cache.get('fx').title,
        imageUrl:wx.$cache.get('fx').img,
        path:`/pages/index/index?pid=${wx.$cache.get('member_id')}`
      }
    }
  },
  onShareTimeline(){
    return {
      title:wx.$cache.get('fx').title,
      imageUrl:wx.$cache.get('fx').img,
      query:`a=${wx.$cache.get('member_id')}`,
    }
  }
})